//商品规格接口
var express = require('express');
var router = express.Router();
const mysql = require('mysql2/promise');

/* GET product_specs listing. */
router.get('/', async function(req, res, next) {
try {
  // 创建一个数据库连接
  const connection = await mysql.createConnection({
    host: 'localhost',
    user: 'root',
    password:'020722',
    database: 'liaoyicheng-uni-app',
  });

  // execute 将在内部调用 prepare 和 query
  const [results, fields] = await connection.execute(
    'SELECT * FROM `product_specs`'
  );

  console.log(results); // 结果集
  console.log(fields); // 额外的元数据（如果有的话）
  res.send(results);
} catch (err) {
  console.log(err);
}
});

module.exports = router;
